// 
var titleHead =$('#titleHead');

// 标题唯一性校验
titleHead.on('change', function() {
	var _this = this,
		data = {
			code: $(this).val()
		},
		url = $(this).data(url);

	$.getJSON(url, data, function(json) {
		if (json.code == 0) {
			createErrorLabel.call(_this, '标题已存在');
			codeStatus = false;
		} else {
			$(_this).siblings('.error').hide();
			codeStatus = true;
		}
	});
});
function createErrorLabel(msg){
    var ele = $(this).siblings('.error'),
      name = $(this).attr('name');

    if (ele.length > 0) {
      ele.text(msg).show();
      return;
    }
    $(this).after('<label id="'+name+'-error" class="error" for="'+name+'">'+msg+'</label>');
}


	// 联动

    $('body').on('mousedown','#firstTerrace .option',function(){
        var id = $(this).data('value');
        var listr = '';
        $('#secondTerrace').html(listr);
        $('#secondTerrace').siblings('input').val('');
        $('#secondTerrace').siblings('.show-option').html('请选择');


        $.ajax({
            url: '/Admin/Information/Information/getColumnListByModule',
            type:'post',
            dataType:'json',
            data:{module_id:id},
            success:function(json){
                console.log(json)
                $.each(json.list,function(i,val){
                    listr += '<div class="option" data-value="'+val.id+'" data-url=""><span>'+val.info_name+'</span></div>';
                    $('#secondTerrace').html(listr);
                })
                
                
            },
            error:function(json){

            }
        })
    })

// 提交

var newsAdd = $('#newsAdd');
newsAdd.validate();

newsAdd.on('submit', function() {
	try {
		
		if (newsAdd.valid()) {
		
	        if (ue.getContent() == "") {
	            $.alert('请输入新闻详情！');
	            return false;
	        }
	        if ($('.list').length < 1) {
	            $.alert('请上传图片！');
	            return false;
	        }
	        if ($('#hw-select-add input').val() == '') {
	            $.alert('请选择栏目！');
	            return false;
	        }
	        newsAdd.submitForm();
		}


	} catch(e) {
		console.error(e);
	}

	return false;
})

// 图片上传初始化

new Upload({
	elem: 'add-img-btn',
	url: '/Api/Upload/ajax_more_img',
	name: 'Filedata[]',
	formId: 'upload-form',
	inputId: 'file-upload-input',
	
})
var status = $('#goods_desc').data('status');
if (status == 0) {
	var ue = UE.getEditor('goods_desc', {
	    readonly: true,
	    autoFloatEnabled: false,
	    initialFrameWidth: 830,
	    initialFrameHeight: 400,
	})
}else{
	var ue = UE.getEditor('goods_desc', {
	    readonly: false,
	    autoFloatEnabled: false,
	    initialFrameWidth: 830,
	    initialFrameHeight: 400,
	})
}
